<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <!-- 引入 Axios -->
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>

<body>
    <!-- 骑手页面 -->
    <!-- longitude:116.408023, latitude: 39.903745  -->
    <!-- longitude: 116.405035, latitude: 39.903187 -->
    <!-- longitude: 116.406756, latitude: 39.904003 -->
    <div id="app">
        <h1>选择骑手</h1>
        <select v-model="riderindex">
            <option v-for="(rider,index) in riderlist" :key="index" :value="index">{{rider.name}}</option>
        </select>
        <ul>
            <li v-for="(item,index) in orderlist" :key="item._id">
                <input type="checkbox" name="" id="" v-model="selectlist" :value="item">{{item.shopname}}--{{item.buyname}}--{{item.phone}}
            </li>
        </ul>
        <button @click="ti">接单</button>
    </div>
    <script>
        // 创建一个简单的Vue实例
        new Vue({
            el: '#app',
            data: {
                riderlist: [],
                riderindex: -1,
                currentrider: {},
                // 订单列表
                orderlist: [],
                // 选中的订单列表
                selectlist: [],
            },
            mounted() {
                axios.get('http://localhost:3000/getRider').then(res => {
                    this.riderlist = res.data.data
                })
                axios.get('http://localhost:3000/getOrder').then(res => {
                    this.orderlist = res.data.data
                })
            },
            // 监听riderindex的值
            watch: {
                riderindex: function () {
                    if (this.riderlist.length > 0) {
                        this.currentrider = this.riderlist[this.riderindex]
                        console.log(this.currentrider);
                    }

                }
            },
            methods: {
                ti() {
                    console.log(this.currentrider);
                    console.log(this.selectlist);
                    // 去后端修改订单信息，改为已接单，并且把数据传递过去
                }
            }

        });
    </script>
</body>

</html>